import type { User } from '@/types/USer.d.ts'
import { defineStore } from 'pinia'
import { ref } from 'vue'
// 引入pinia存储
export const useUSerStore = defineStore(
  'cp-User',
  () => {
    // 设置用户  一开始为空
    const user = ref<User>()
    //设置函数存储用户信息
    const SetUser = (u: User) => {
      user.value = u
    }
    // 删除用户的信息
    const delUSer = () => {
      user.value = undefined
    }
    const returnUrl = ref('')
    const setReturnUrl = (url: string) => (returnUrl.value = url)
    return {
      user,
      SetUser,
      delUSer,
      returnUrl,
      setReturnUrl
    }
  },
  {
    persist: true
  }
)
